/**
 * yry
 * 2017-02-20
 */
(function () {
    var serverData = {};
    var	serverTable;
    
  //查询1
    jQuery('#search-btn').on('click', function() {
    	serverData.year = jQuery('#nian').val();
    	jQuery.ajax({
			type : 'get',
			url : window.rootPath+ '/ui/payBackToArticle/getMyTrance',
			data :{
				'year':jQuery('#nian').val()
			},
			dataType : 'json',
			contentType : 'application/json;charset=utf-8',
			success : function(data) {
				valuation(data);
			}
		});
	});
    
    jQuery(document).ready(function () {
    	var sel = document.getElementById('nian');
    	var date = new Date();
    	
    	for(var j=2;j>=0;j--){
    		var opt = document.createElement('option');
    		opt.value = date.getFullYear()+j;
    		opt.innerHTML = date.getFullYear()+j;
    		sel.appendChild(opt);
    		if(j==0){
    			opt.selected="selected"
    		}
    	}
    	for(var i=0;i<6;i++)
    	{
    		var opt = document.createElement("option");
    		opt.value = (date.getFullYear()-i-1);
    		opt.innerHTML = (date.getFullYear()-i-1);
    		sel.appendChild(opt);
    	}
    	
    	serverData.year = jQuery('#nian').val();
    	
    	jQuery.ajax({
			type : 'get',
			url : window.rootPath+ '/ui/payBackToArticle/getMyTrance',
			data :{
				'year':jQuery('#nian').val()
			},
			dataType : 'json',
			contentType : 'application/json;charset=utf-8',
			success : function(data) {
				valuation(data);
			}
		});
    });
    //将数据显示到页面对应的单元格内
    function valuation(data){
    	var all=0;
		for(var g=0;g<12;g++){
			var a;
			if(g<9){
				a=jQuery('#nian').val()+"-0"+(g+1);
			}else{
				a=jQuery('#nian').val()+"-"+(g+1);
			}
			var hang = 0;
			for(var h=0;h<3;h++){
				var b;
				if(h==0)b="销售处";
				if(h==1)b="成套处";
				if(h==2)b="外贸处";
				var c = ""+g+h;
				document.getElementById(c).innerHTML = 0;
				for(var k=0;k<data.data.length;k++){
					if(data.data[k].superior==b&&data.data[k].dPaidDate==a){
						document.getElementById(c).innerHTML = data.data[k].nPaidSum;
						all+=data.data[k].nPaidSum;
						continue;
					}
				}
				hang += parseFloat(document.getElementById(c).innerHTML);
			}		
			document.getElementById(""+g+"3").innerHTML = hang;
		}
		document.getElementById("123").innerHTML = all;
		for(var i=0;i<3;i++){
			var lie = 0;
			for(var j=0;j<12;j++){
				lie += parseFloat(document.getElementById(""+j+i).innerHTML);
			}
			document.getElementById("12"+i).innerHTML = lie;
		}
    }
})();
